<?

/*	Text.extend OBJECT
*	Methods:
*	output
*
*	Constructor:
*
*
*					*/


class TextExtend extends modTEXT {

	function __construct( $vars ) {
		
		$this->_addvars( $vars );
		$this->_ref();
	}
	
	public function construct() {
		global $DB, $Page, $Object;

		$Object = new OBJECT( $this->vars->type, (int) $_GET['id'] );
		
		$Page->set_cache( "title", $Object->get( 'name' ));
		
	}
	
	public function output() {
	
		if( $this->action )
			$nodes = $this->{ "filter_" . $this->action }();
			
		$this->addclass( $this->action );
		
		$result = ( $nodes ) ?
			( is_array( $nodes )? "<ul class='{$this->action}'>" . implode("\n", $nodes ) . "</ul>\n" : $nodes ) : "empty.";
	
	
		return $this->parse( $result ) . $this->render_js();
	}
	
#	Simple iFrame Builder.
	function filter_iframe() {
		global $Object;
		
		if( !$this->vars->src )
			$this->vars->src = $Object->get( 'url' );
		
		return "<iframe src='{$this->vars->src}'></iframe>";		
	}
	
	
	function filter_numslide() {
		global $DB, $Engine;
		
		if( !$this->vars->condt )
			$this->vars->condt = "ID in(" . implode( ",", $this->vars->children ) . ")";
			
		$this->vars->children = array();
		
		if( $this->vars->type == "page" )			
			if( $objs = $DB->filter_pages( $this->vars->condt ))
				foreach( $objs as $obj )
					$this->vars->children[] = array( "title"=> $obj->get( "title" ), "descr"=> $Engine->text->get( $obj->get( "textid" ), "long" ), "imgid" => $obj->get( "imgid" ), "link" => $obj->uri());
		
		else
			if( $objs = $DB->filter_objects( $this->vars->type, $this->vars->condt ))
				foreach( $objs as $obj )
					$this->vars->children[] = array( "title"=> $obj->get( "name" ), "descr"=> $obj->get( "content" ), "imgid" => $obj->media->get( "media.img" ), "link" => $obj->uri());

		unset( $this->vars->condt );
		$this->js = "
			mod = new TextExtend( '{$this->action}', " . json_encode( $this->vars ) . " );
		";
		
	}
	
	
#	Deprecated?
	
	private function filter_links() {
		global $Engine;
		
		if( $this->vars->nodes )
			foreach( $this->vars->nodes as $node ) {
				
				$uri = ( $node->id && $page = new PAGE( $node->id )) ? $page->parse_uri() : $node->ext;

				$title = ( $node->nameid )? $Engine->text->get( $node->nameid ) :
					( ( $page )? $page->get( "title" ) : array_pop( explode( "//", $node->ext )) );
				
				$nodes[] = $this->render_node( $uri, $title, ($node->ext) );
			}

		return $nodes;
	}
	
	private function render_node( $uri, $title = '...', $ext = false ) {

		return "<li><a href='$uri'". (( $ext )? " target='_blank'":"") .">$title</a></li>";
	}
}

/*

{"mod":"text.extend", "class":"wgt", "action":"links", "nameid":1754, "tleref":{"h":"h3"}, "vars": {
	"nodes":[ { "ext":"http://jazzandsounds.com", "nameid":1755 }, { "id":20 } ]
} }

*/ 

?>